
/*
 * Copyright 2008 Friendster Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
 
 * Unless required by applicable law or agreed to in writing, 
 * software distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
*/

using System;
using System.Collections;
using System.Text;

namespace Friendster.Service
{
    /// <summary>
    /// Represents a single photo with all of it's data.
    /// </summary>
    public sealed class Photo : FriendsterEntity
    {
        // Fields
        private bool _createdDateTransformed = false;
        
        // Methods
        // Initialize data.
        internal Photo(Hashtable photoState) : base((Hashtable)photoState["photo"])
        {
            photoState = (Hashtable)photoState["photo"];
        }

        private DateTime TransformCreatedDate()
        {
            DateTime time = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            string seconds = (string)(base.GetState<string>("created"));
            time = time.AddSeconds(Convert.ToDouble(seconds));
            base["created"] = time;
            this._createdDateTransformed = true;
            return time;
        }

        // Properties
        /// <summary>
        /// Returns the photo ID.
        /// </summary>
         public string ID
        {
            get
            {
                return (base.GetState<string>("pid") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns user ID of photo owner.
        /// </summary>
        public string OwnerID
        {
            get
            {
                return (base.GetState<string>("owner") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the URL of this photo's medium size version.
        /// </summary>
        public string MediumImageUrl
        {
            get
            {
                return (base.GetState<string>("src") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the URL of this photo's small size version.
        /// </summary>
        public string SmallImageUrl
        {
            get
            {
                return (base.GetState<string>("src_small") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the URL of this photo's large size version.
        /// </summary>
        public string LargeImageUrl
        {
            get
            {
                return (base.GetState<string>("src_big") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the URL of this photo's original version.
        /// </summary>
        public string LinkUrl
        {
            get
            {
                return (base.GetState<string>("link") ?? string.Empty);
            }
        }
        /// <summary>
        /// Retirns the photo caption or title.
        /// </summary>
        public string Caption
        {
            get
            {
                return (base.GetState<string>("caption") ?? string.Empty);
            }
        }
        /// <summary>
        /// Returns the datetime object of when the photo has been uploaded.
        /// </summary>
        public DateTime CreatedDate
        {
            get
            {
                if (!this._createdDateTransformed)
                {
                    return this.TransformCreatedDate();
                }
                return (DateTime)base["created"];
            }
        }
        /// <summary>
        /// Returns a boolean value indicating whether the photo is grabbed from another user's album or not.
        /// </summary>
        public bool IsGrabbed
        {
            get
            {
                string val = base.GetState<string>("is_grabbed");
                return (val=="1");
            }
        }
    }
}
